﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VersionComparer.DataModel;

namespace VersionComparer.UI
{
    public partial class ItemsListControl : UserControl
    {


        
        #region fields
        TextBox dummy;
        //ItemsListControlDropdownForm form;
        #endregion fields

        #region constructors
        public ItemsListControl(ItemNamePairLists items, bool source)
        {
            Items = items;
            IsSource = source;
            InitializeComponent();
            Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            dummy = new  TextBox();
            dummy.Top = 3000;
            Controls.Add(dummy);
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        #endregion constructors

        #region properties
        bool IsSource
        {
            get;
            set;
        }
        ItemNamePairLists Items
        {
            get;
            set;
        }
        public ItemNamePairList SelectedItems
        {
            get
            {
                return comboBox1.SelectedValue as ItemNamePairList;
            }
            set
            {
                comboBox1.SelectedValue = value;
            }
        }
        #endregion properties

        private void ItemsListControl_Resize(object sender, EventArgs e)
        {
        }
        private void richTextBox1_Enter(object sender, EventArgs e)
        {
            //this.Height = 100;
        }
        private void richTextBox1_Leave(object sender, EventArgs e)
        {
            //this.Height = MinimumSize.Height; ;
        }
        private void comboBox1_Enter(object sender, EventArgs e)
        {
            /*
            if (form != null)
            {
                dummy.Focus();
                form.Focus();
                
            }
            else
            {
                form = new ItemsListControlDropdownForm(this);
                form.FormClosed += form_FormClosed;
                form.Show(FindForm());
                
            }
             * */
        }
        private void form_FormClosed(object sender, FormClosedEventArgs e)
        {
            /*
            form = null;
            dummy.Focus();
             * */
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        public void RefreshItems()
        {
            var selected = SelectedItems;
            comboBox1.Items.Clear();
            foreach (var item in Items)
                comboBox1.Items.Add(item);
            if (selected != null)
                SelectedItems = selected;
            else
            {
                if (IsSource && comboBox1.Items.Count > 0)
                    SelectedItems = comboBox1.Items[0] as ItemNamePairList;
            }

        }
    }
}
